package com.issac.webflux.demo.consumer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;

/**
 * @author: ywy
 * @date: 2023-10-29
 * @desc:
 */
@SpringBootApplication
public class WebFluxConsumerApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebFluxConsumerApplication.class, args);
    }

    @RestController
    class EmployeeController {
        @GetMapping(value = "employees", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
        public Flux<Employee> findAll() {
            return WebClient.create("localhost:8080/employees").get().retrieve()
                    .bodyToFlux(Employee.class);
        }
    }
}
